package com.dosen.api.third.party.cmp.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0
 * @author: guangcheng
 * @date: 2023/1/12 12:17
 * @description:
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "cmp.net")
public class CmpApiProperties {

    private String env;
    private String protocol;
    private String token;
    // dev
    private String devloginport;
    private String devhost;
    private String devport;
    private String devusername;
    private String devpassword;
    // prod
    private String prodloginport;
    private String prodhost;
    private String prodport;
    private String produsername;
    private String prodpassword;


    public String getPreUrlOfLogin() {
        String realhost = getRealHost();
        String realport = getRealLoginPort();
        if ("80".equals(realport)) {
            return protocol + "://" + realhost;
        } else {
            return protocol + "://" + realhost + ":" + realport;
        }
    }

    public String getPreUrl() {
        String realhost = getRealHost();
        String realport = getRealPort();
        if ("80".equals(realport)) {
            return protocol + "://" + realhost;
        } else {
            return protocol + "://" + realhost + ":" + realport;
        }
    }

    public String getRealHost() {
        return "prod".equals(env) ? prodhost : devhost;
    }

    public String getRealPort() {
        return "prod".equals(env) ? prodport : devport;
    }

    public String getRealLoginPort() {
        return "prod".equals(env) ? prodloginport : devloginport;
    }

    public String getRealUsername() {
        return "prod".equals(env) ? produsername : devusername;
    }

    public String getRealPassword() {
        return "prod".equals(env) ? prodpassword : devpassword;
    }
}

